// 分类相关 API 封装：获取树形分类
import client from './client'

// 获取分类树：GET /api/category/tree
export async function getCategoryTree() {
  const res = await client.get('/category/tree')
  // 期望结构：{ code: 200, message: '操作成功', data: [...] }
  return res
}

// 新增分类：POST /api/category
// payload 字段示例：{ name, parentId, level?, sort, status(1/0), description }
export async function createCategory(payload) {
  const res = await client.post('/category/add', payload)
  return res
}

// 更新分类：PUT /api/category/{id}
export async function updateCategoryApi(id, payload) {
  const res = await client.put(`/category/${id}`, payload)
  return res
}

// 删除分类：DELETE /api/category/{id}
export async function deleteCategoryApi(id) {
  const res = await client.delete(`/category/${id}`)
  return res
}

// 批量更新状态：POST /api/category/status/batch
// body: { ids: number[], status: 1 | 0 }
export async function batchSetCategoryStatus(ids, status) {
  const res = await client.post('/category/status/batch', { ids, status })
  return res
}

// 更新排序：PATCH /api/category/{id}/sort  或 PUT /api/category/{id}
export async function updateCategorySort(id, sort) {
  const res = await client.patch(`/category/${id}/sort`, { sort })
  return res
}